package com.wxj.likou.date241230;

import java.util.ArrayList;
import java.util.List;

public class Yanghuisanjiao {

    public static void main(String[] args) {
        generate(4);
    }

    public static List<List<Integer>> generate(int num) {
        List<List<Integer>> list = new ArrayList<>();
        int maxSize = 0;
        for (int i = 0; i < num; i++) {
            List<Integer> currentList = new ArrayList<>();
            int lastIndex = 0;
            List<Integer> lastArr = new ArrayList<>();
            if (i - 1 > 0) {
                lastIndex = i - 1;
                lastArr = list.get(lastIndex);
            }
            for (int j = 0; j <= i; j++) {
                int el = 1;

                if (j != 0 && j != i) {
                    int a = lastArr.get(j);
                    int b = lastArr.get(j - 1);
                    el = a + b;
                }
                if ((el + "").length() > maxSize) {
                    maxSize = (el + "").length();
                }
                currentList.add(el);
            }
            list.add(currentList);
        }
        maxSize = maxSize + 2;
        for (int i = 0; i < list.size(); i++) {
            double mm = (double) (num - i) / 2;
            // 如果是整数
            if (mm % 1 == 0 && mm >= Integer.MIN_VALUE && num <= Integer.MAX_VALUE) {
                for (int j = 0; j < (int) mm; j++) {
                    for (int k = 0; k < maxSize; k++) {
                        System.out.print(" ");
                    }
                }

            } else {
                for (int j = 0; j < (int) mm; j++) {
                    for (int k = 0; k < maxSize; k++) {
                        System.out.print(" ");
                    }
                }
                for (int k = 0; k < maxSize / 2; k++) {
                    System.out.print(" ");
                }

            }

            List<Integer> currentList = list.get(i);

            for (int j = 0; j < currentList.size(); j++) {
                int el = currentList.get(j);
                int xx = maxSize - (el + "").length();
                //前半段在后面
//                if (j >= currentList.size() / 2) {
//                    for (int k = 0; k < xx; k++) {
//                        System.out.print(" ");
//                    }
//                }

                System.out.print(el);
                for (int k = 0; k < xx; k++) {
                        System.out.print(" ");
                }
                // 后关短在前面
//                if (j < currentList.size() / 2) {
//                    for (int k = 0; k < xx; k++) {
//                        System.out.print(" ");
//                    }
//                }
            }
            System.out.println();
        }

        return list;
    }
}
